package com.help10000.rms.ui.windows

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.amir.common.beans.RepairInfo
import com.amir.common.beans.Ware
import com.amir.common.holder.CommonViewHolder
import com.amir.common.mvp.base.BasePopuWindow
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.mvp.view.IView
import com.help10000.rms.R
import com.help10000.rms.ui.adapter.SelectPickingAdapter

class SelectPickingPopuWindow(context: Context?, contentView: View?, width: Int, height: Int,  wares: List<Ware>,repairInfo: RepairInfo) :
    BasePopuWindow<BasePresenter<IView?>?, IView?>(context, contentView, width, height) {
    var  wares: List<Ware> = mutableListOf()
    var  holder: CommonViewHolder ?= null
    var repairInfo: RepairInfo ?= null
    init {
        this.wares = wares
        this.repairInfo = repairInfo
        initData()
    }

    private fun initData() {
        val linearLayoutManager = LinearLayoutManager(mContext)
        val rv_list = holder?.getView<RecyclerView>(R.id.rv_list)
        rv_list?.layoutManager = linearLayoutManager

        val pickingAdapter = SelectPickingAdapter(mContext, wares, R.layout.item_select_picking,repairInfo)
        rv_list?.adapter = pickingAdapter
        pickingAdapter.setOnItemClickListener {
            if (onSelectResultListener != null){
                onSelectResultListener?.onResult(wares[it])
                dismiss()
            }
        }
    }

    override fun initBindHolder(holder: CommonViewHolder) {
       this.holder = holder
    }

    override fun createPresenter(): BasePresenter<IView?>? {
        return null
    }
    var onSelectResultListener:OnSelectResultListener ?= null
    interface OnSelectResultListener{

        fun onResult(wares: Ware)
    }
}